package com.cema.manage.invoke;


import com.cema.manage.invoke.interfase.TestAttributeUtilsInterFase;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;


public class TestAttributeUtils implements TestAttributeUtilsInterFase {
    // 过滤字符串
    public static final String FILTER_PROTECTED = "protected";
    public static final String FILTER_PRIVATE = "private";

    private static TestAttributeUtils attributeUtils;

    public static TestAttributeUtils getInstance() {
        if (attributeUtils == null) {
            attributeUtils = new TestAttributeUtils();
        }
        return attributeUtils;
    }

    private TestAttributeUtils() {
    }

    @Override
    public String[] getAttributeName(Class<?> c, String filterModifier) {
        List<String> strList = new ArrayList<String>();
        Field[] fields = c.getDeclaredFields();
        for (Field field : fields) {// 获取字段名
            String modifier = Modifier.toString(field.getModifiers());
            if (filterModifier.equals(modifier)) {
                strList.add(field.getName());
            }
        }
        return strList.toArray(new String[strList.size()]);
    }

}
